<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script src="/weather/city.js"></script>
<script>

    const now_date = Date.now();
    let s = getCode("成都");
    const url = "http://d1.weather.com.cn/sk_2d/" + s + ".html?_=" + now_date;

    const httpRequest = new XMLHttpRequest();//第一步：建立所需的对象
    httpRequest.open('GET', url, true);//第二步：打开连接  将请求参数写在url中  ps:"./Ptest.php?name=test&nameone=testone"
    // 在服务器端设置CORS响应头
    httpRequest.setRequestHeader('Access-Control-Allow-Origin', '*'); // 允许所有域
    httpRequest.setRequestHeader('Content-Type', 'application/json');
    httpRequest.setRequestHeader('Authorization', 'Bearer token');
    httpRequest.send();//第三步：发送请求  将请求参数写在URL中

    /**
     * 获取数据后的处理程序
     */
    httpRequest.onreadystatechange = function () {
        if (httpRequest.readyState === 4 && httpRequest.status === 200) {
            var json = httpRequest.responseText;//获取到json字符串，还需解析
            console.log(json);
        }
    };
</script>
</body>
</html>
